function sayHi3(): string {
  return "这是一段字符串文本";
}
let hi: string = sayHi3();

function countSum(x: number, y: number): number {
  return x + y;
}
let sumInput = countSum(1, 3);
console.log(sumInput);
//参数默认值
function helloasd(name?: string): void {
  if (name) return console.log(`my name is ${name}`);
  console.log(`my name is WXS`);
}
helloasd();

function helloasd2(name: string = "WXS") {
  if (name) return console.log(`my name is ${name}`);
}
helloasd2();

function buyGun(gunName: String, count: number): void {
  console.log(
    `有眼光~[${gunName}]是村里最亮的枪,送你[${count}]把,我们P城来相见`
  );
}
buyGun("M416", 3);
//可选参数参数
function buyGun1(gunName: String, count?: number): void {
  console.log(
    `有眼光~[${gunName}]是村里最亮的枪,送你[${
      count ? count : 1
    }]把,我们P城来相见`
  );
}
buyGun1("M416", 5);
//函数默认值
function buyGun3(gunName: String = "M416", count: number = 1): void {
  console.log(
    `有眼光~[${gunName}]是村里最亮的枪,送你[${count}]把,我们P城来相见`
  );
}
// buyGun3("AK47", 5);
//前面不传写undefined后面传
buyGun3(undefined, 3);

//剩余参数
function addSum(x: number, y: number, ...restOfNum: number[]) {
  //创建一个求和变量保存求和结果,将x和y的值求和后传入
  let resNum: number = x + y;
  //使用for of遍历剩余参数,并累加到求和变量中
  for (const ele of restOfNum) {
    resNum += ele;
  }
  //将结果打印
  console.log("打印结果:" + resNum);
}
addSum(1.2, 2);
addSum(1, 23, 4, 5, 6, 7, 8, 9, 0);
